<template>
  <el-container style="height: 950px; border: 1px solid #eee">
    <el-aside width="350px" >
      <el-container >
        <!--   患者选择区      -->
        <el-header style="padding: 0;margin: 0">
          <el-row>
            <el-col :span="21" style="text-align: left">
              <el-tag>患者选择：</el-tag>
            </el-col>
            <el-col :span="3" style="text-align: right">
              <el-button type="primary"  size="small" @click="reloadUser" style="margin-right: 5px">
                <el-icon><Refresh/></el-icon>
              </el-button>
            </el-col>
          </el-row>
          <el-row>
            <el-input placeholder="请输入内容" v-model="inputPatient"  style="width: 100%">
              <template #prepend>
                患者名：
              </template>
              <template #append>
                <el-icon><Search/></el-icon>
              </template>
            </el-input>

          </el-row>
        </el-header>
        <el-main style="height: 800px;padding: 0;margin: 0">
          <el-tabs type="border-card" >
            <el-tab-pane label="本人" >
              <el-tag size="small" >未诊患者：</el-tag>
              <el-table ref="singleTable" :data="RegistersTable01" highlight-current-row @row-click="handleCurrentChange01"
                        style="width: 100%;height: 50%" :show-header="false" max-height="400" size="small">
                <el-table-column property="casenumber" label="病历号" width="80">
                </el-table-column>
                <el-table-column property="realname" label="姓名" >
                </el-table-column>
                <el-table-column property="age" label="年龄" width="50">
                </el-table-column>
              </el-table><br/><br/>
              <el-tag size="small" >已诊患者：</el-tag>
              <el-table ref="singleTable" :data="RegistersTable02" @row-click="handleCurrentChange02"
                        @row-dblclick = "handleDBCurrentChange"
                        style="width: 100%;height: 50%" :show-header="false" size="small">
                <el-table-column property="casenumber" label="病历号" width="80">
                </el-table-column>
                <el-table-column property="realname" label="姓名" >
                </el-table-column>
                <el-table-column property="age" label="年龄" width="50">
                </el-table-column>
              </el-table>
            </el-tab-pane>
            <el-tab-pane label="科室*">
              <el-tag>未诊患者：</el-tag>

              <el-table ref="singleTable" :data="MyPatientsData01" highlight-current-row @row-click="handleCurrentChange01"
                        style="width: 100%;height: 50%" :show-header="false" size="small">
                <el-table-column property="casenumber" label="病历号" width="80">
                </el-table-column>
                <el-table-column property="realname" label="姓名" >
                </el-table-column>
                <el-table-column property="age" label="年龄" width="50">
                </el-table-column>
              </el-table>
              <el-tag>已诊患者：</el-tag>
              <el-table ref="singleTable" :data="MyPatientsData02" @row-click="handleCurrentChange02"
                        style="width: 100%;height: 50%" :show-header="false" size="small">
                <el-table-column property="casenumber" label="病历号" width="80">
                </el-table-column>
                <el-table-column property="realname" label="姓名" >
                </el-table-column>
                <el-table-column property="age" label="年龄" width="50">
                </el-table-column>
              </el-table>
            </el-tab-pane>
          </el-tabs>
        </el-main>
      </el-container>
    </el-aside>

    <el-container direction="vertical" style="height: 950px">
      <el-row>

        <span style="margin-left: 20px;font-size: small;" :span="20">{{showPatientsTop}}</span>
        <el-button type="text" size="small" style="float: right;margin-right: 20px;" @click="endRegister" v-if="showStop" :span="2">诊毕</el-button>

      </el-row>

      <!--
        门诊主要功能区
      -->
      <el-tabs type="border-card" :before-leave="toTab">
        <!-- 患者检查填写  -->
        <el-tab-pane label="病历首页">
          <!-- 1. 门诊病历 -->
          <el-container v-loading="loading">


            <!-- 页面正文 -->
            <el-main style="width:100%;background:#fff;height:800px;overflow-y: auto">
              <el-form ref="form" :model="medicalRecord01" label-width="80px" label-position="left" size="small" >
                <el-row style="background-color: #EAF1F5;margin-top: -20px">
                  <el-col :span="8" style="margin-top: 4px;">

                  </el-col>
                  <el-col :span="4" >
                    <el-button type="text" size="small"  @click="stageCheck">暂存</el-button>
                  </el-col>
                  <el-col :span="4" >
                    <el-button type="text" size="small"  @click="saveCheck">提交</el-button>
                  </el-col>
                  <el-col :span="4" >
                    <el-button type="text" size="small"  :disabled="isSaved" @click="cleanCheck">清空所有</el-button>
                  </el-col>
                  <el-col :span="4" >
                    <el-button type="text" size="small"  @click="refMedicalRecord">刷新</el-button>
                  </el-col>
                </el-row>
                <el-tag>病史内容：</el-tag>
                <el-form-item label="主诉">
                  <el-input type="textarea" :rows="1" v-model="medicalRecord01.readme" :disabled="isSaved"></el-input>
                </el-form-item>
                <el-form-item label="现病史">
                  <el-input type="textarea" :rows="2" v-model="medicalRecord01.present" :disabled="isSaved"></el-input>
                </el-form-item>
                <el-form-item label="现病治疗情况">
                  <el-input type="textarea" :rows="2" v-model="medicalRecord01.presenttreat" :disabled="isSaved"></el-input>
                </el-form-item>
                <el-form-item label="既往史">
                  <el-input type="textarea" :rows="2" v-model="medicalRecord01.history" :disabled="isSaved"></el-input>
                </el-form-item>
                <el-form-item label="过敏史">
                  <el-input type="textarea" :rows="2" v-model="medicalRecord01.allergy" :disabled="isSaved"></el-input>
                </el-form-item>
                <el-form-item label="体格检查">
                  <el-input type="textarea" :rows="2" v-model="medicalRecord01.physique" :disabled="isSaved"></el-input>
                </el-form-item>
                <el-form-item label="诊断">
                  <el-input type="textarea" :rows="2" v-model="medicalRecord01.diagnosis" :disabled="isSaved"></el-input>
                </el-form-item>

                <el-form-item label="检查建议">
                  <el-input type="textarea" :rows="2" v-model="medicalRecord01.proposal" :disabled="isSaved"></el-input>
                </el-form-item>
                <el-form-item label="注意事项">
                  <el-input type="textarea" :rows="2" v-model="medicalRecord01.careful" :disabled="isSaved"></el-input>
                </el-form-item>
              </el-form>
              <el-button type="text" size="small"  @click="saveCheck" >提交</el-button>
            </el-main>

          </el-container>
        </el-tab-pane>
        <el-tab-pane label="检查申请*" :lazy="true">
          <div  >
            <!-- 2.检验申请 -->
            <el-container direction="horizontal">
              <!-- 页面弹窗 -->
              <el-dialog
                  title="新增检查申请"
                  v-model="dialogVisible"
                  width="30%">
                <el-form size="small">
                  <el-form-item>
                    <el-input
                        placeholder="请输入内容"
                        v-model="search.itemname"
                        style="width: 100%"
                    >
                      <template #prepend>
                        检验名称：
                      </template>
                      <template #append>
                        <el-button type="text" @click="searchcheck"> <!-- 修复：使用组件图标 + 文本按钮样式 -->
                          <el-icon><Search /></el-icon>
                        </el-button>
                      </template>
                    </el-input>
                  </el-form-item>
                  <el-form-item>
                    <el-table border :data="checklist" highlight-current-row size="small" height="200px">
                      <el-table-column prop="choosen" label="" width="30px">
                        <template #default="scope">
                          <input type="radio" name="choosen" :value="scope.row.id" v-model="checkclickid" @change=""/>
                        </template>
                      </el-table-column>
                      <el-table-column property="itemcode" label="项目编号" width="80">
                      </el-table-column>
                      <el-table-column property="itemname" label="项目名称" >
                      </el-table-column>
                    </el-table>
                  </el-form-item>
                  <el-form-item label="检验科室" >
                    <el-select  placeholder="请选择" v-model="search.deptid" @change="searchcheck">
                      <el-option
                          v-for="item in deptselect"
                          :key="item.id"
                          :label="item.deptname"
                          :value="item.id">
                      </el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="是否加急：" >
                    <el-switch
                        v-model="isurgent"
                        :active-value="1"
                        :inactive-value="0"
                        active-color="#13ce66">
                    </el-switch>
                  </el-form-item>
                  <el-form-item>
                    <el-button type="primary" @click="addcheck">确 定</el-button>
                    <el-button @click="dialogVisible = false">取 消</el-button>
                  </el-form-item>
                </el-form>
              </el-dialog>


              <!-- 页面正文 -->
              <el-aside  style="width: 1100px;height: 500px;">

                <el-row style="background-color: #EAF1F5">
                  <el-col :span="4" >
                    <el-tag size="small">本项目金额合计：</el-tag>
                    <el-tag type="warning" size="small">
                      {{ totalAmount.toFixed(2) }}
                    </el-tag>
                  </el-col>
                  <el-col :span="3"><el-button type="text" size="small"  @click="()=> { dialogVisible = true; load() }">新增项目</el-button></el-col>
                  <el-col :span="3"><el-button type="text" size="small"  @click="deleteselect">删除项目</el-button></el-col>
                  <el-col :span="2"><el-button type="text" size="small"  @click="addapply">开立</el-button></el-col>

                </el-row>

                <el-form ref="form"  label-width="120px">
                  <el-row>
                    <el-col :span="22" style="margin-top: 4px;">
                      <el-table ref="singleTable" :data="checktable" @selection-change="handleCheckSelectionChange"
                                style="width: 1200px;margin:10px;padding: 10px;" :show-header="true">
                        <el-table-column type="selection" :selectable="checkSelectable">
                      </el-table-column>
                        <el-table-column property="name" label="项目" width="120">
                        </el-table-column>
                        <el-table-column property="checkoperid" label="执行科室" width="80">
                        </el-table-column>
                        <el-table-column property="isurgent" label="是否加急" width="80">
                          <template #default="scope">
                            {{ scope.row.isurgent === 1 ? '加急' : scope.row.recordtype === 0 ? '正常':'正常' }}
                          </template>
                        </el-table-column>
                        <el-table-column property="state" label="状态" width="80">
                          <template #default="scope">
                            {{ scope.row.state === 0 ? '未开具' : scope.row.state === 1 ? '已开具':scope.row.state === 2 ? '已缴费':scope.row.state === 3 ? '已检查':scope.row.state === 4 ? '已完成':'未知' }}
                          </template>
                        </el-table-column>
                        <el-table-column property="num" label="单价" width="80">
                        </el-table-column>
                        <el-table-column label="目的要求" width="100">
                          <template #default="scope">
                            <el-input
                                v-model="scope.row.objective"
                                placeholder="输入目的要求..."
                                size="small"
                                :disabled="scope.row.state !== 0"
                            ></el-input>
                          </template>
                        </el-table-column>
                        <el-table-column property="result" label="检查结果" width="80">
                          <template slot-scope="scope">
                            <el-popover
                                placement="right"
                                width="400"
                                trigger="click">
                              <img src=""></img>
                              <el-button slot="reference" type="text" size="small">查看</el-button>
                            </el-popover>

                          </template>
                        </el-table-column>

                      </el-table>

                    </el-col>
                  </el-row>

                </el-form>
              </el-aside>
              <el-main style="margin-top: -20px;">
                <el-tabs type="card" v-model="activeName">


                </el-tabs>
              </el-main>
            </el-container>

          </div>
        </el-tab-pane>
        <!-- 患者病历填写  -->
        <el-tab-pane label="门诊确诊*" :lazy="true">
          <el-table
              :data="checklasttable"
              @selection-change="handleChecklastSelectionChange"
              style="margin-top: 20px;"
              border
              stripe
          >
            <el-table-column type="selection" width="55" :selectable="checkSelectablelast"/>
            <el-table-column prop="name" label="检验名称" />
            <el-table-column prop="num" label="单价" />
            <el-table-column property="isurgent" label="是否紧急" >
              <template #default="scope">
                {{ scope.row.isurgent === 1 ? '加急' : scope.row.recordtype === 0 ? '正常':'正常' }}
              </template >
            </el-table-column>
            <el-table-column property="state" label="状态" >
              <template #default="scope">
                {{ scope.row.state === 0 ? '未开具' : scope.row.state === 1 ? '已开具':scope.row.state === 2 ? '已缴费':scope.row.state === 3 ? '已检查':scope.row.state === 4 ? '已完成':'未知' }}
              </template>
            </el-table-column>
            <el-table-column label="门诊结果" width="100">
              <template #default="scope">
                <el-input
                    v-model="scope.row.result"
                    placeholder="输入诊断"
                    size="small"
                    :disabled="scope.row.state !== 3"
                ></el-input>
              </template>
            </el-table-column>
          </el-table>
          <br>
          <div class="action-buttons">
            <el-button
                type="primary"
                @click="executeSelected"
                :disabled="!selectedlastCheckItems.length"
            >
              执行确认
            </el-button>
          </div>
        </el-tab-pane>


      </el-tabs>
    </el-container>
  </el-container>
</template>


<script setup>
import {computed, onMounted, reactive, ref} from 'vue'
import {ElNotification, ElMessageBox} from 'element-plus'
import service from '@/utils/request'
import {Search, Refresh} from "@element-plus/icons-vue";
import { useCounterStore } from "@/stores/counter.js";
const counter = useCounterStore();
// 定义响应式数据
let checkapply = ref({})
let medicalRecord01 = ref({})
let showPatientsTop = ref("请选择患者")
let inputPatient = ref('')
let RegistersTable01 = ref([])
let RegistersTable02 = ref([])
let MyPatientsData01 = ref([])
let MyPatientsData02 = ref([])
let dialogVisible = ref(false)
let tableData02 = ref([])
let deptselect = ref([])
let switch01 = ref(false)
let msg01 = ref('')
let activeName = ref('')
let isSaved = ref(false)
let showStop = ref(false)
let loading = ref(false)
let search=ref({})
let checklist=ref([])
let checktable=ref([])
let checkclickid=ref()
let isurgent=ref(0)
let currentpatient=ref({})
const selectedCheckItems = ref([]);
const selectedlastCheckItems = ref([]);
let filteredCheckTable=ref([])
const checklasttable= computed(() =>
    filteredCheckTable.value.filter(item => item.state > 2 & item.state <5)
);
// 计算选中项目的总金额
const totalAmount = computed(() => {
  return selectedCheckItems.value.reduce((sum, item) => {
    return sum + (parseFloat(item.num) || 0);
  }, 0);
});

// 处理表格选择变化
function handleCheckSelectionChange(selection) {
  selectedCheckItems.value = selection;
  console.log('选中的检查项目:', selection);
  console.log('总金额:', totalAmount.value);
}
function handleChecklastSelectionChange(selection) {
  selectedlastCheckItems.value = selection;

}
// 重新加载用户数据
function reloadUser() {
  // 这里可以添加重新加载数据的逻辑
  load()
  ElNotification({
    title: '提示',
    message: '重新加载用户数据',
    type: 'info'
  })
}
function executeSelected()  {
  console.log(selectedlastCheckItems.value)
  selectedlastCheckItems.value.forEach(item => {
    item.resultoperid = counter.vo_user.value.id;
  });
  service.post("/check/allcompleted",selectedlastCheckItems.value).then(
      res => {
        console.log("addapply")
        console.log(res.data)
        if(res){
          console.log("addapply：true")
          updatedata()
          ElNotification({
            title: '成功',
            message: `已提交检查`,
            type: 'success'
          });
        }
      }
  )
}
// 处理单行点击事件（本人未诊患者）
function handleCurrentChange01(row) {
  currentpatient=row
  updatedata()
  ElNotification({
    title: '提示',
    message: `选择了本人未诊患者：${row.realname}`,
    type: 'info'
  })
}

// 处理单行点击事件（本人已诊患者）
function handleCurrentChange02(row) {
  currentpatient=row
  updatedata()
  ElNotification({
    title: '提示',
    message: `选择了本人已诊患者：${row.realname}`,
    type: 'info'
  })
}

function updatedata(){
  console.log("updatedata")
  showPatientsTop.value = `当前患者：${currentpatient.realname}`
  medicalRecord01.value=[]
  medicalRecord01.value.casenumber=currentpatient.casenumber
  medicalRecord01.value.id=currentpatient.id
  console.log("row")
  console.log(currentpatient)
  service.post("/medicalrecord/search", {casenumber:currentpatient.casenumber}).then(
      res => {
        console.log("search")
        medicalRecord01.value = res.data
        medicalRecord01.value.casenumber=currentpatient.casenumber
        medicalRecord01.value.registid=currentpatient.id
        console.log(res)
      }
  )
  console.log("currentpatient.id")
  console.log(currentpatient.id)

  service.post("/check/listbyregistid?registid="+ currentpatient.id).then(
      res => {
        console.log("listbyregistid")
        console.log(res.data)
        checktable.value = res.data
        filteredCheckTable.value=res.data
        console.log(checktable.value)
      }
  )
}

// 双击选中患者
function handleDBCurrentChange(row) {
  showPatientsTop.value = `当前患者：${row.realname}`
  ElNotification({
    title: '提示',
    message: `双击选择了患者：${row.realname}`,
    type: 'info'
  })
}

// 暂存病历信息
function stageCheck() {
  // 这里可以添加暂存数据的逻辑
  console.log("暂存")
  console.log(medicalRecord01.value)
  console.log("暂存")
  medicalRecord01.value.casestate=1
  service.post("/medicalrecord/add",medicalRecord01.value).then(
      res => {
        if(res){
          console.log("插入成功")
        }else {
          console.log("插入失败")
        }

      })
  ElNotification({
    title: '提示',
    message: '病历信息已暂存',
    type: 'success'
  })
}

// 提交病历信息
function saveCheck() {
  // 这里可以添加提交数据的逻辑
  medicalRecord01.value.casestate=2
  console.log("提交")
  console.log(medicalRecord01.value)
  service.post("/medicalrecord/add",medicalRecord01.value).then(
      res => {
        if(res){
          console.log("插入成功")
        }else {
          console.log("插入失败")
        }

      })
  service.post("/register/change", {casenumber:medicalRecord01.value.casenumber}).then(
      res => {
        if(res){
          console.log("就诊状态更改成功")
          console.log(medicalRecord01.value)
        }else {
          console.log("就诊状态更改失败")
        }

      })
  ElNotification({
    title: '提示',
    message: '病历信息已提交',
    type: 'success'
  })
  load()
}

// 清空所有病历信息
function cleanCheck() {
  medicalRecord01.value = {}
  isSaved.value = false
  ElNotification({
    title: '提示',
    message: '病历信息已清空',
    type: 'info'
  })
}

// 刷新病历信息
function refMedicalRecord() {
  // 这里可以添加刷新数据的逻辑
  load()
  ElNotification({
    title: '提示',
    message: '病历信息已刷新',
    type: 'info'
  })
}

// 诊毕操作
function endRegister() {
  // 这里可以添加诊毕的逻辑
  showPatientsTop.value = '请选择患者'
  showStop.value = false
  ElNotification({
    title: '提示',
    message: '本次诊断已结束',
    type: 'info'
  })
}

// 切换标签页的前置钩子
function toTab() {
  // 这里可以添加切换标签页的逻辑
  return true
}

// 显示确认框
function showConfirm(message) {
  ElMessageBox.confirm(
      message,
      '提示',
      {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }
  ).then(() => {
    ElNotification({
      title: '成功',
      message: '操作已确认',
      type: 'success'
    })
  }).catch(() => {
    ElNotification({
      title: '取消',
      message: '操作已取消',
      type: 'info'
    })
  })
}

function load(){
  console.log("load()")
  console.log(counter.vo_user.value.id)
  service.post("/check/getfmed").then(
      res => {
        console.log("检查的查询单元")
        search.value=res.data
        console.log(search)
      }
  )


  service.post("/medicalrecord/list").then(
      res => {
        console.log(res.data)
      }
  )

  service.post("/register/list?visitstate=1&userid="+counter.vo_user.value.id).then(
      res => {
        RegistersTable01.value = res.data
        console.log(RegistersTable01.value)
      }
  )

  service.post("/register/list?visitstate=2&userid="+counter.vo_user.value.id).then(
      res => {
        RegistersTable02.value = res.data
        console.log(RegistersTable02.value)
      }
  )

  service.post("/register/list1?visitstate=1&deptid="+counter.vo_user.value.deptID).then(
      res => {
        console.log("1?")
        MyPatientsData01.value = res.data
        console.log(MyPatientsData01.value)
      }
  )

  service.post("/register/list1?visitstate=2&deptid="+counter.vo_user.value.deptID).then(
      res => {
        MyPatientsData02.value = res.data
        console.log(MyPatientsData02.value)
      }
  )

  service.post("/dept/depttype?depttype=2").then(
      res => {
        console.log("科室")
        deptselect.value = res.data
        console.log(deptselect.value)
      }
  )

  checklist.value=null
}

function searchcheck() {
  console.log("查询项目中")
  console.log(search.value)
  service.post("/check/searchcheck",{itemname:search.value.itemname,deptid:search.value.deptid}).then(
      res => {
        checklist.value = res.data
        console.log(checklist.value)
      }
  )
}

function addcheck() {
  dialogVisible.value = false;
  console.log("addcheck")
  console.log(checkclickid.value)
  // 查找选中的项目
  const item = checklist.value.find(item => item.id === checkclickid.value);
  console.log(item)
  if (item) {
    // 创建新的检查申请对象，属性名全部小写
    const newCheckApply = {
      // 基本信息（从 checklist 中获取）
      medicalid: medicalRecord01.value.casenumber || 0,     // 病历ID
      registid: medicalRecord01.value.registid || 0, // 挂号ID
      itemid: item.id,                // 项目ID
      name: item.itemname,            // 项目名称
      objective: '',                  // 目的要求（可在表单中补充）
      position: '',                   // 检查部位（可在表单中补充）
      isurgent: isurgent.value,       // 是否加急
      num: item.price,                         // 数量默认为1
      creationtime: new Date().toISOString(), // 当前时间
      doctorid: counter.vo_user.value.id,     // 开立医生ID
      checkoperid: item.deptid,       // 检查人员ID（假设 DeptID 对应 CheckOperID）
      resultoperid: 0,                // 结果录入人员ID（初始值）
      checktime: null,                // 检查时间（初始为空）
      result: '',                     // 检查结果（初始为空）
      resulttime: null,               // 结果时间（初始为空）
      state: 0,                       // 状态（初始值）
      recordtype: item.recordtype     // 记录类型
    };

    // 添加到表格数据
    checktable.value = [...checktable.value, newCheckApply];

    console.log('添加到表格的数据:', newCheckApply);
    console.log('当前表格数据:', checktable.value);

    ElNotification({
      title: '成功',
      message: `已添加检验项目: ${item.ItemName}`,
      type: 'success'
    });
  } else {
    console.error('未找到选中的检验项目，checkclickid:', checkclickid.value);

    ElNotification({
      title: '错误',
      message: '未找到选中的项目，请重试',
      type: 'error'
    });
  }
}

function checkSelectable(row, index) {
  return row.state === 0; // 只有状态为0（未开具）的行才可选择
}
function checkSelectablelast(row, index) {
  return row.state === 3; // 只有状态为0（未开具）的行才可选择
}
function deleteselect() {
  // 获取选中的项目中状态为0（未开具）的项目
  const selectedUnopenedItems = selectedCheckItems.value.filter(item => item.state === 0);

  // 如果没有可删除的项目
  if (selectedCheckItems.value.length > 0 && selectedUnopenedItems.length === 0) {
    ElNotification({
      title: '提示',
      message: '只能删除未开具的项目',
      type: 'warning'
    });
    return;
  }

  // 如果没有选中任何项目
  if (selectedCheckItems.value.length === 0) {
    ElNotification({
      title: '提示',
      message: '请先选择要删除的项目',
      type: 'warning'
    });
    return;
  }

  // 确认删除对话框
  ElMessageBox.confirm(
      '确定要删除选中的未开具项目吗？',  // 直接使用固定消息
      '提示',
      {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }
  ).then(() => {
    // 过滤掉状态为0的项目，保留其他项目
    checktable.value = checktable.value.filter(item => {
      // 如果项目不在选中列表中或状态不为0，则保留
      return !selectedCheckItems.value.some(selected => selected.itemid === item.itemid) || item.state !== 0;
    });

    // 清空选中状态
    selectedCheckItems.value = [];

    ElNotification({
      title: '成功',
      message: `已删除 ${selectedUnopenedItems.length} 个未开具的项目`,
      type: 'success'
    });
  }).catch(() => {
    ElNotification({
      title: '取消',
      message: '操作已取消',
      type: 'info'
    });
  });
}

function addapply(){
  service.post("/check/addapply",selectedCheckItems.value).then(
      res => {
        console.log("addapply")
        console.log(res.data)
        if(res){
          console.log("addapply：true")
          console.log(currentpatient)
          service.post("/check/listbyregistid?registid="+ currentpatient.id).then(
              res => {
                console.log("listbyregistid")
                console.log(res.data)
                checktable.value = res.data;
                console.log(checktable.value)
              }
          )
          ElNotification({
            title: '成功',
            message: `已提交检查`,
            type: 'success'
          });
        }
      }
  )
}

onMounted(() => {
  // 加载本人 已诊患者、未诊患者，本科室已诊患者，未诊患者
  console.log("钩子启动")
  load()
})
</script>